<?php

/**
 * An abstract service controller that automatically checks for a valid OAuth request.
 * 
 * @author Michael Krotscheck
 */
class Core_OAuth_Controller_Abstract extends Zend_Controller_Action
{

	/**
	 * The OAuth Provider
	 *
	 * @var Core_OAuth_Provider
	 */
	protected $provider;

	/**
	 * Shut down the normal renderer.
	 *
	 * @see Zend_Controller_Action::init()
	 */
	public function preDispatch ()
	{
		parent::preDispatch();

		// Since this is a service endpoint, we're disabling the layout
		$this->_helper->viewRenderer->setNoRender();
		$this->_helper->layout->disableLayout();

		// Retrieve the system configured oauth provider
		$this->provider = Core_Resource::locate('oauthprovider');

		// Validate the request.
		$result = $this->provider->validate_request();
		if ($result !== null)
		{
			echo $result;
			die();
		}
	}
}
